home *** CD-ROM | disk | FTP | other *** search
/ The Game Master (3rd Edition) / The Game Master 3rd edition.iso / files / windonal / fuzzgen / testbool.c < prev    next >
Text File  |  1992-08-05  |  4KB  |  196 lines

  1. /* This code was produced by FUZZGEN, the Fuzzy    */
  2. /* Logic Code Generator from Alston Software Labs. */ 
  3.  
  4.  
  5. /* The following is the GLOBAL variable list:      */
  6.  
  7.  
  8.  
  9. #define d1l 0
  10. #define d1r 40
  11. #define apex1l 0
  12. #define apex1r 10
  13. #define d2l 10
  14. #define d2r 90
  15. #define apex2 50
  16. #define d3l 60
  17. #define d3r 100
  18. #define apex3l 80
  19. #define apex3r 100
  20. #define d4l 35.77
  21. #define d4r 67.543
  22.  
  23. /*
  24.    Functions that use these variables follow.
  25.    Functions are NUMBERED and use the SAME NUMBER
  26.    variables. For instance, Function DECISION1 uses
  27.    apexl1, apexr1, etc...
  28. */ 
  29.  
  30.  
  31. double Decision1( double testdata, double blo, 
  32.                      double bhi, double ap1, double ap2 )
  33. {
  34.  
  35.     double Membership, baseL, baseR, ratioL, ratioR;
  36.  
  37.  
  38.    /*  Exit if data not in bounds... */
  39.  
  40.     if (testdata < blo) return 0;
  41.     if (testdata > bhi) return 0;
  42.     
  43.    /*   Data is within set boundry... */
  44.     
  45.     baseL = ap1 - blo;
  46.     baseR = bhi - ap1;
  47.     ratioL = 0;
  48.     ratioR = 0;
  49.     
  50.     /*  Normalise test data  */
  51.     
  52.     if (baseL > 0) ratioL = 100 / baseL;
  53.     if (baseR > 0) ratioR = 100 / baseR;
  54.  
  55.     /*   TRAPEZOIDAL  */
  56.     
  57.     if((testdata >= ap1) && (testdata <= ap2))
  58.        Membership = 100.0;
  59.     if(testdata <= ap1)
  60.        Membership = (testdata - baseL) * ratioL;
  61.     if(testdata > ap2)
  62.        Membership = (baseR - (testdata + ap2)) * ratioR;
  63.   
  64.     return(Membership);
  65. }
  66.  
  67.  
  68.  
  69.  /* Use of the ABOVE function is as follows:
  70.  
  71.  
  72. (double)var = Decision1(DATA_TO_TEST, d1l, d1r, apex1l, apex1r);
  73.  
  74.  */
  75.  
  76.  
  77.  
  78. double Decision2( double testdata, double blo, 
  79.                      double bhi, double ap1, double ap2 )
  80. {
  81.  
  82.     double Membership, baseL, baseR, ratioL, ratioR;
  83.  
  84.  
  85.    /*  Exit if data not in bounds... */
  86.  
  87.     if (testdata < blo) return 0;
  88.     if (testdata > bhi) return 0;
  89.     
  90.    /*   Data is within set boundry... */
  91.     
  92.     baseL = ap1 - blo;
  93.     baseR = bhi - ap1;
  94.     ratioL = 0;
  95.     ratioR = 0;
  96.     
  97.     /*  Normalise test data  */
  98.     
  99.     if (baseL > 0) ratioL = 100 / baseL;
  100.     if (baseR > 0) ratioR = 100 / baseR;
  101.  
  102.     /*   TRIANGULAR   */
  103.     
  104.     if (testdata <= ap1)   // left of apex 
  105.        Membership = (testdata - baseL) * ratioL;
  106.     else
  107.        Membership = (baseR - (testdata + ap1)) * ratioR;
  108.   
  109.     return(Membership);
  110. }
  111.  
  112.  
  113.  
  114.  /* Use of the ABOVE function is as follows:
  115.  
  116.  
  117. (double)var = Decision2(DATA_TO_TEST, d2l, d2r, apex2, 0 );
  118.  
  119.  */
  120.  
  121.  
  122.  
  123. double Decision3( double testdata, double blo, 
  124.                      double bhi, double ap1, double ap2 )
  125. {
  126.  
  127.     double Membership, baseL, baseR, ratioL, ratioR;
  128.  
  129.  
  130.    /*  Exit if data not in bounds... */
  131.  
  132.     if (testdata < blo) return 0;
  133.     if (testdata > bhi) return 0;
  134.     
  135.    /*   Data is within set boundry... */
  136.     
  137.     baseL = ap1 - blo;
  138.     baseR = bhi - ap1;
  139.     ratioL = 0;
  140.     ratioR = 0;
  141.     
  142.     /*  Normalise test data  */
  143.     
  144.     if (baseL > 0) ratioL = 100 / baseL;
  145.     if (baseR > 0) ratioR = 100 / baseR;
  146.  
  147.     /*   TRAPEZOIDAL  */
  148.     
  149.     if((testdata >= ap1) && (testdata <= ap2))
  150.        Membership = 100.0;
  151.     if(testdata <= ap1)
  152.        Membership = (testdata - baseL) * ratioL;
  153.     if(testdata > ap2)
  154.        Membership = (baseR - (testdata + ap2)) * ratioR;
  155.   
  156.     return(Membership);
  157. }
  158.  
  159.  
  160.  
  161.  /* Use of the ABOVE function is as follows:
  162.  
  163.  
  164. (double)var = Decision3(DATA_TO_TEST, d3l, d3r, apex3l, apex3r);
  165.  
  166.  */
  167.  
  168.  
  169.  
  170. double Decision4( double testdata, double blo, 
  171.                      double bhi, double ap1, double ap2 )
  172. {
  173.  
  174.     double Membership, baseL, baseR, ratioL, ratioR;
  175.  
  176.  
  177.    /*  Exit if data not in bounds... */
  178.  
  179.     if (testdata < blo) return 0;
  180.     if (testdata > bhi) return 0;
  181.     
  182.     return(100.0); /* Boolean Function and data good */
  183. }
  184.  
  185.  
  186.  
  187.  /* Use of the ABOVE function is as follows:
  188.  
  189.  
  190. (double)var = Decision4(DATA_TO_TEST, d4l, d4r, apex3l, apex3r);
  191.  
  192.  */
  193.  
  194.  
  195.  
  196.